﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Ajeelee.Core.Database;
using Ajeelee.Core.Utils;
using AiLuWeb.Business;
using AiLuWeb.Model;
using AiLuWeb.WebSite.Code;

namespace AiLuWeb.WebSite
{
    public partial class productlist : PageBase
    {
        protected int id;
        protected string title;
        Hashtable table = new Hashtable();
        protected NewsClass curClass = new NewsClass();
        protected NewsClass curParClass = new NewsClass();
        protected IList<Products> productsList = new List<Products>();
        IProductsBusiness productsBll = new ProductsBusinessFactory().CreateProductsBusiness();
        protected PageStructure ps = new PageStructure() { CurrPage = 1, PageSize = 20 };

        protected void Page_Load(object sender, EventArgs e)
        {
            // 获取参数
            id = QueryParamInt32("id");
            title = QueryParam("title");

            if (id > 0)
            {
                curClass = Utility.GetNewsClass().FirstOrDefault(c => c.Id == id);
                if (curClass != null)
                {
                    lefter1.ProductCId = curClass.Id;

                    curParClass = Utility.GetNewsClass().FirstOrDefault(c => c.Id == curClass.PId);

                    table.Add(ProductsHash.CId, curClass.Id);
                    productsList = productsBll.GetAllProductsByPage(table, ps);
                    this.pager.PageStruct = ps;
                }
                else
                {
                    curClass = new NewsClass();
                    Page_GoTo("/404.aspx?id=4042");
                }
            }
            else if (title.IsNotNullAndEmpty())
            {
                table.Add(NewsHash.Title, Function.SafeSqlLiteral(title));
                productsList = productsBll.GetAllProductsByPage(table, ps);
                this.pager.PageStruct = ps;
            }
            else
            {
                curClass = new NewsClass();
                Page_GoTo("/404.aspx?id=4041");
            }
        }
    }
}